package com.friend.joey.applicationfriend.Database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

import static android.R.attr.id;

/**
 * Created by Joey on 2017/4/24.
 */

public class MyDatabaseHelper extends SQLiteOpenHelper {
    public static final String CREATE_USER="create table user ("
            +"id integer primary key autoincrement,"
            +"username text,"
            +"userpassword text,"
            +"usersign text,"
            +"familyid integer,"
            +"side integer)";
    public static final String CREATE_FRIEND="create table friend ("
            +"id integer primary key autoincrement,"
            +"friendname1 text,"
            +"friendsign1 text,"
            +"friendid1 integer,"
            +"friendname2 text,"
            +"friendsign2 text,"
            +"friendid2 integer)";
    public static final String CREATE_TALK="create table talk ("
            +"id integer primary key autoincrement,"
            +"userid integer,"
            +"day text,"
            +"time text,"
            +"txt text,"
            +"side integer)";
    public static final String CREATE_TALKMAS="create table talkmas ("
            +"id integer primary key autoincrement,"
            +"day text,"
            +"time text,"
            +"txt text,"
            +"side1 integer,"
            +"side2 integer)";
    public static final String CREATE_TALKCHILD="create table talkchild ("
            +"id integer primary key autoincrement,"
            +"day text,"
            +"time text,"
            +"txt text,"
            +"side integer)";
    public static final String CREATE_FORGET="create table forget ("
            +"id integer primary key autoincrement,"
            +"title text,"
            +"content text,"
            +"addtime text,"
            +"alerttime text,"
            +"addid integer,"
            +"type integer)";
    public static final String CREATE_ALERTMESSAGE="create table message ("
            +"id integer primary key autoincrement,"
            +"title text,"
            +"content text,"
            +"time text,"
            +"type integer)";

    private Context mContext;

    public MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_USER);
        db.execSQL(CREATE_FRIEND);
        db.execSQL(CREATE_TALK);
        db.execSQL(CREATE_TALKMAS);
        db.execSQL(CREATE_TALKCHILD);
        db.execSQL(CREATE_FORGET);
        db.execSQL(CREATE_ALERTMESSAGE);
        Toast.makeText(mContext,"Create successed",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists user");
        db.execSQL("drop table if exists friend");
        db.execSQL("drop table if exists talk");
        db.execSQL("drop table if exists talkmas");
        db.execSQL("drop table if exists talkchild");
        db.execSQL("drop table if exists forget");
        db.execSQL("drop table if exists message");
        onCreate(db);
    }
}
